/**
 * <a-button v-if="$auth('form.edit')">Button</a-button>
 * @param Vue
 */
function plugin (Vue) {
  if (plugin.installed) {
    return
  }
  !Vue.prototype.$auth && Object.defineProperties(Vue.prototype, {
    $auth: {
      get () {
        const _this = this
        return (permissions) => {
          const [permission, action] = permissions.split('.')
          const permissionList = _this.$store.getters.roles
          return permissionList.find((val) => {
            return val.moduleKey === permission
          }).moduleRoot.findIndex((val) => {
            return val === action
          }) > -1
        }
      }
    }
  })
}

export default plugin
